var api = require('../../utils/api.js');
var app = getApp();



Page({

    /**
     * 页面的初始数据
     */
    data: {
        goods: [],
        goodtitle: ''
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onShow() {
        var that = this;
        api.get({
            url: 'wxapp/index/gettamegoods',
            data: {},
            success: data => {
                var goods = data.data;

                that.setData({
                    goods: goods
                })



            }
        });
    },

    getvalue(ret) {
        console.log(ret);

        var indea = ret.currentTarget.dataset.indexa;
        var indeb = ret.currentTarget.dataset.indexb;
        var value = ret.detail.value;

        var goods = this.data.goods;

        goods[indea].down[indeb].count=value;

       console.log(goods);

        this.setData({
            goods:goods
        })


    },

    submits(){
        var goods = this.data.goods;

        var goodstitle='';
        var number=0;
        goods.forEach(function(index){

            console.log(index);
            var downs=index.down;

            downs.forEach(function(down){

                if(down.count>0){

                    goodstitle+=down.name+'*'+down.count+' ';

                    number=number+parseInt(down.count);
                }

            })


        })
        
        console.log(goodstitle)

        let pages = getCurrentPages();//获取page
        let prevPage = pages[pages.length-2];//上一个页面（父页面）
        prevPage.setData({
            goodstitle:goodstitle,
            number:number
          })
          
          //返回上一页面
          wx.navigateBack({
            delta: 1
          })

    }

})